/*
 * @Author: your name
 * @Date: 2021-09-15 10:43:13
 * @LastEditTime: 2022-09-23 16:19:07
 * @LastEditors: zshawk1982
 * @Description: In User Settings Edit
 * @FilePath: \media_system\database\models\article.js
 */
var moment = require("moment");
module.exports = (sequelize, DataTypes) => {
  const Knowledge = sequelize.define(
    "knowledge",
    {
      knowledgeId: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        comment: "知识ID",
      },
      title: {
        type: DataTypes.STRING,
        comment: "知识标题",
      },
      summary: {
        type: DataTypes.STRING,
        comment: "摘要",
      },
      content: {
        type: DataTypes.TEXT,
        comment: "内容",
      },
      type: {
        //0血糖 1饮食 2其他
        type: DataTypes.INTEGER,
        comment: "知识类型",
      },
      views: {
        type: DataTypes.INTEGER,
        comment: "浏览量",
      },
      logoImg: {
        type: DataTypes.TEXT,
        comment: '知识列表logo图片'
      },
      avator: {
        type: DataTypes.STRING,
        comment: "知识标题封面",
      },
      weight: {
        type: DataTypes.INTEGER,
        comment: "权重(知识排序)",
      },
      createdAt: {
        type: DataTypes.DATE,
        get() {
          const createdAt = this.getDataValue("createdAt");
          return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
        },
        set(createdAt) {
          return this.setDataValue("createdAt", createdAt);
        },
      },
      updatedAt: {
        type: DataTypes.DATE,
        get() {
          const updatedAt = this.getDataValue('updatedAt')
         return moment(updatedAt).format('YYYY-MM-DD HH:mm:ss');
        },
        set(updatedAt) {
          return this.setDataValue('updatedAt',updatedAt)
        }
      }
    },
    {
      tableName: "knowledges",
      timestamps: true,
      // hooks: {
      //   afterFind: async function(query) {
      //     console.log(555555555,query)
      //   },
      // }
    }
  );

  return Knowledge;
};
